#include <bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn = 1005;
int a[maxn], b[maxn], c[maxn], d[maxn], e[maxn];
int dp[maxn][maxn];
int n, m;

void solve(){
	cin >> n >> m;
	for (int i=1;i<=n;i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i];
	}
	
	for (int i=1;i<=n;i++) {
		for (int j=0;j<=m;j++) {
			// 不倒
			dp[i][j] = dp[i-1][j] + e[i];
			// 倒 ai
			if (j >= a[i]) {
				dp[i][j] = max(dp[i][j], dp[i-1][j-a[i]] + b[i]);
 			}
			// 倒 ci
			if (j >= c[i]) {
				dp[i][j] = max(dp[i][j], dp[i-1][j-c[i]] + d[i]);
			}
//			cout << i << ' ' << j << ' '<< dp[i][j] << '\n';
		}
	}
	cout << dp[n][m] << '\n';
	
	
	
}

signed main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	solve();
	return 0;
}
